<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <title>下拉刷新+无限加载</title>
    <style>
        html,
        body {
            margin: 0;
            padding: 0;
            height: 100%;
            background: #dadada;
        }

        /*header {*/
            /*height: 44px;*/
            /*line-height: 44px;*/
            /*text-align: center;*/
            /*background: #da020c;*/
            /*color: #fff;*/
        /*}*/

      /*  header > a {
            height: 34px;
            line-height: 34px;
            position: absolute;
            top: 5px;
            left: 10px;
        }*/

        /*h1 {*/
            /*margin: 0;*/
            /*padding: 0;*/
            /*font-size: 18px;*/
            /*font-weight: normal;*/
        /*}*/



        #scroller {
            margin: 0;
            padding: 0;
        }

        .item {
            height: 60px;
            line-height: 60px;
            border-bottom: 1px solid #ddd;
            text-indent: 1em;
            background: #fff;
        }

        .jroll-infinite-tip {
            height: 44px;
            line-height: 44px;
            text-align: center;
        }
    </style>
    <script src="node_modules/jroll/src/jroll.js"></script>
    <script src="node_modules/jroll-pulldown/jroll-pulldown.js"></script>
    <script src="node_modules/jroll-infinite/jroll-infinite.js"></script>
    <style id="jroll_style">
        /* jroll-infinite */
        .jroll-infinite-hide > * {
            display: none
        }

        .jroll-infinite-hideimg img {
            display: none
        }
    </style>
</head>

<body>

<div id="wrapper" style="overflow: hidden;">
    <div id="scroller" jroll-id="jroll_79915017"
         style="min-height: 100%; touch-action: none; transform: translate(0px, 0px) translateZ(0px) scale(1);">
        <div class="jroll-infinite-tip">正在加载...</div>
    </div>
    <div class="jroll-ybar"
         style="position: absolute; top: 2px; right: 2px; bottom: 2px; width: 6px; overflow: hidden; border-radius: 2px; transform: scaleX(0.5);">
        <div class="jroll-ybtn"
             style="background: rgba(0, 0, 0, 0.4) none repeat scroll 0% 0%; position: absolute; top: 0px; left: 0px; right: 0px; border-radius: 2px; height: 242px; transform: translate(0px, 0px) translateZ(0px) scale(1);"></div>
    </div>
    <div class="jroll-plugin-pulldown"
         style="position: absolute; top: -44px; width: 100%; height: 44px; line-height: 44px; font-size: 16px; text-align: center; transform: translate(0px, 0px) translateZ(0px) scale(1);">
        <span class="jroll-plugin-pulldown-icon"
              style="display: inline-block; width: 24px; height: 24px; position: absolute; top: 10px; left: 25%; transform: rotateZ(0deg);"><img
                style="width:24px;height:24px;display:block;"
                src=""></span><span
            class="jroll-plugin-pulldown-text">下拉刷新</span></div>
</div>

<script>
    //模拟ajax
    function ajax(parms) {
        var a = [],
                i;
        var page = parms.url.replace("getData.do?page=", "");
        for (i = 1; i <= 4; i++) {
            a.push({
                "index": i + (page - 1) * 4,
                "text": "下拉刷新+无限加载"
            });
        }
        setTimeout(function () {
            parms.success(a);
        }, 800);
    }

    var jroll = new JRoll("#wrapper", {
        scrollBarY: true
    });

    //下拉刷新
    jroll.pulldown({
        refresh: function (complete) {
            jroll.options.page = 1;
            jroll.scrollTo(0, 44, 0, true);  //滚回顶部
            ajax({
                url: "getData.do?page=" + 1,
                success: function (data) {
                    complete();
                    jroll.scroller.innerHTML = "";    //清空内容
                    jroll.infinite_callback(data);
                }
            });
        }
    });

    //无限加载
    jroll.infinite({
        getData: function (page, callback) { //获取数据的函数，必须传递一个数组给callback
            ajax({
                url: "getData.do?page=" + page,
                success: function (data) {
                    callback(data);
                }
            });
        },
        template: "<div class='item'>{{=_obj.index}}、{{=_obj.text}}</div>" //每条数据模板
    });
</script>


</body>
</html>